package com.itqf.demo04;

import com.itqf.job.MyJob;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;
import org.quartz.impl.calendar.CronCalendar;

/**
 * @Description:
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2020/11/19
 * @Time: 下午3:17
 */
public class TestNotExcuteTask {

    public  static  void  main(String[]args) throws  Exception{
        //1.创建调度器
        Scheduler scheduler = new StdSchedulerFactory().getScheduler();
        //2.创建JobDetail
        JobDetail  jobDetail = JobBuilder.newJob(MyJob.class).
        withIdentity("myJob","myGroup").build();
        //3.创建某一天不执行的日历对象
        CronCalendar cronCalendar = new CronCalendar("1-30 * 15 19 11 ?");
        //4.设置不执行的日历
        scheduler.addCalendar("notRun",cronCalendar,false,false);
        //5.创建触发器
        CronTrigger cronTrigger = TriggerBuilder.newTrigger()
                .withSchedule(CronScheduleBuilder.cronSchedule("* * * * * ?"))
                .withIdentity("myTrigger","myGroup")
                .modifiedByCalendar("notRun")//.modifiedByCalendar  指定不触发的日历对象
                .build();

        //6.注册触发器和任务
        scheduler.scheduleJob(jobDetail,cronTrigger);

        //7.启动任务
        scheduler.start();
        //为了看定时任务的效果
        Thread.sleep(100000);
        //关闭定时任务
        scheduler.shutdown();



    }
}
